package com.ydgk.dao;

import com.ydgk.db.JDBCUtils;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public abstract class BaseDao<T> {
    //第页分5条
    public int pageCount = 10 ;
    //1. 获取JDBCTemplate对象
    protected JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());

    public abstract int save(T t);

    public abstract int updateById(T t);

    public abstract int deleteById(int id);

    public abstract List<T> findAll();

    public abstract T findById(int id);

    public abstract List<T> paging(int pageNumber);

    public int maxPage(String tableName){
        String sql = "select count(*) from "+tableName;
        long t = template.queryForObject(sql, Long.class);
        int total = (int)t;//将long类型转换成int类型
        return total % pageCount == 0 ? total / pageCount : total / pageCount + 1 ;
    }


}
